<?php
namespace app\admin\controller;

use think\Controller;
use think\Request;
use app\admin\model\Menu;

class BaseController extends Controller
{
	protected $data = [];
	public $meta_title;
	public $breadcrumb;
	public $curr_menu_info;  // 当前菜单的信息

	public function initialize()
	{	
		$routeInfo = $this->request->routeInfo();
		$currentRule = $routeInfo['rule'];
		$menuName = explode('/', $currentRule);
		if (!empty($menuName[1])) {
			$currentMenu = $menuName[1];
		}else{
			$currentMenu = 'home';
		}
		$this->curr_menu_info = Menu::getCurrentMenu($currentMenu);
		$this->meta_title = Menu::getMetaTitle($currentMenu);
		$this->breadcrumb = Menu::getBreadcrumb($currentMenu);
		$menus = Menu::getHtmlMenu();
		$this->assign([
			'meta_title' => $this->meta_title,
			'breadcrumb' => $this->breadcrumb,
			'menus' => $menus,
			'curr_menu_info' => $this->curr_menu_info,
			'controller'	=> $this->request->controller()
		]);
	}
}
